<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.mselect.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.mselect.js?"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.multiselect.js"></script>
<script type="text/javascript">
$(function(){
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$(".view").toggle(function(){
		$(this).parent().parent().next().show();
	},function(){
		$(this).parent().parent().next().hide();
	});
	$("#multiselect").multiselect({height: 260, minWidth: 160});
});
</script>
<fieldset><legend>查询条件</legend>
<form method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>
		<select name="op">
			<option value="sales_time" <?php if (isset($_GET['op']) && $_GET['op'] == 'sales_time')echo "selected='selected'"?>>销售日期</option>
			<option value="shipped_time" <?php if (isset($_GET['op']) && $_GET['op'] == 'shipped_time')echo "selected='selected'"?>>出库日期</option>
		</select>
	</th>
	<td>
		<input name="begin_shipped_time" value="<?=isset($_GET['begin_shipped_time']) ? $_GET['begin_shipped_time'] : date('Y-m-01', CURRENT_TIMESTAMP)?>" class="datepicker" /> to
		<input name="end_shipped_time" value="<?=isset($_GET['end_shipped_time']) ? $_GET['end_shipped_time'] : date('Y-m-d', CURRENT_TIMESTAMP)?>" class="datepicker" />
	</td>
</tr>
<tr>
	<th>周期</th>
	<td>
		<label><input name="period" type="radio" value="daily" <?=(isset($_GET['period'])&&$_GET['period']=='daily')?"checked='checked'":''?> />日报表</label>&nbsp;&nbsp;
		<label><input name="period" type="radio" value="weekly" <?=(isset($_GET['period'])&&$_GET['period']=='weekly')?"checked='checked'":''?> />周报表</label>&nbsp;&nbsp;
		<label><input name="period" type="radio" value="monthly" <?=((isset($_GET['period'])&&$_GET['period']=='monthly')||!isset($_GET['period']))?"checked='checked'":''?> />月报表</label>
	</td>
</tr>
<tr>
	<th>选择店铺</th>
	<td>
		<select name="shop_id[]" multiple="multiple" id="multiselect">
		<?foreach ($shop as $s):?>
		<option value="<?=$s['id']?>" <?if (isset($_GET['shop_id']) && is_array($_GET['shop_id']) && in_array($s['id'], $_GET['shop_id']))echo "selected='selected'";elseif (isset($_GET['shop_id']) && $_GET['shop_id'] == $s['id'])echo "selected='selected'"?>><?=$s['name']?></option>
		<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<td><input type="hidden" name="is_search" value="1" /></td>
	<td><input type="submit" class="button" value="查询" /></td>
</tr>
</table>
</form>
</fieldset>
<?if (isset($result)):?>
<table class="list_table" width="100%">
<tr>
	<th>日期</th>
	<th>总重量（克）</th>
	<th>总订单数</th>
	<th>总运费（元）</th>
</tr>
<?php $weight = $quantity = $amount = 0;?>
<?foreach ($result as $r):?>
<?php $weight += $r['weight']; $quantity += $r['quantity']; $amount += $r['amount'];?>
<tr>
	<td title="<?=date("m.d", strtotime($r['begin'])).'-'.date("m.d", strtotime($r['end']))?>"><a class="view" href="javascript:void(0);"><?=($_GET['period']=='daily')?date('Y-m-d', strtotime($r['begin'])):(($_GET['period']=='weekly')?'第'.date('W',strtotime($r['begin'])).'周':date('Y-m',strtotime($r['begin'])))?></a></td>
	<td><?=$r['weight']?></td>
	<td><?=$r['quantity']?></td>
	<td><?=sprintf('%.2f', $r['amount'])?></td>
</tr>
<tr class="detail" style="display: none;">
	<td colspan="25">
		<table width="100%" class="list_table">
			<tr>
				<th>邮寄方式</th>
				<th>重量（克）</th>
				<th>订单数</th>
				<th>运费（元）</th>
			</tr>
			<?php foreach ($r['data'] as $rd):?>
			<tr>
				<td><?php echo $rd['name']?></td>
				<td><?php echo $rd['weight']?></td>
				<td><?php echo $rd['quantity']?></td>
				<td><?php echo $rd['amount']?></td>
			</tr>
			<?php endforeach;?>
		</table>
	</td>
</tr>
<?endforeach;?>
<tr>
	<td>总计</td>
	<td><?=sprintf('%.2f', $weight)?></td>
	<td><?=$quantity?></td>
	<td><?=sprintf('%.2f', $amount)?></td>
</tr>
</table>
<?endif;?>
<?php $this->_endblock();?>